package com.kun.lagou.controller;

import com.kun.lagou.entity.User;
import com.kun.lagou.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author Administrator
 */

//原始格式
//@Controller
//json格式
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/")
    @ResponseBody
    @Transactional(readOnly = true)
    public String getBeijing() {
        return this.userService.findByUsername("aaa").getBirthday();
    }

    /**
     * @PathVariable是用来获得请求url中的动态参数的
     * @param name
     * @return
     */
    @RequestMapping(value = "/{name}", method = RequestMethod.GET)
    public Map<String, Object> getCity(@PathVariable String name) {
        User user =  this.userService.findByUsername(name);

        Map<String, Object> response = new LinkedHashMap<>();
        response.put("msg", "get user with name(" + name +")");
        response.put("user", user);
        return response;
    }
}
